package com.xbongbong.saas.script.tempenum;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.enums.DefaultValueEnum;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.paas.field.SerialNumberPoJo;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.BomBillEnum;
import com.xbongbong.saas.enums.dictionary.BomStatusEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.sys.enums.RoleEnum;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import lombok.Getter;

/**
 * @author long.rao
 * @version v1.0
 * @date 2019/1/17 19:35
 * @since v1.0
 */
@Getter
public enum TempBomBillEnum {
    //
    BASE_INFO(BomBillEnum.BASE_INFO),
    SHEET_NO(BomBillEnum.SHEET_NO),
    NAME(BomBillEnum.NAME),
    STATUS(BomBillEnum.STATUS),
    MEMO(BomBillEnum.MEMO),
    VERSION(BomBillEnum.VERSION),
    PRODUCT(BomBillEnum.PRODUCT),
    MATERIEL(BomBillEnum.MATERIEL),
    OWNER_ID(BomBillEnum.OWNER_ID),
    COUSERID(BomBillEnum.COUSERID),

    SYSTEM_INFO(BomBillEnum.SYSTEM_INFO),
    CREATOR_ID(BomBillEnum.CREATOR_ID),
    ADD_TIME(BomBillEnum.ADD_TIME),
    UPDATE_TIME(BomBillEnum.UPDATE_TIME),

    VERSION_LINK_TEXT(BomBillEnum.VERSION_LINK_TEXT),
    PRODUCT_NAME(BomBillEnum.PRODUCT_NAME),
    PRODUCT_NO(BomBillEnum.PRODUCT_NO),
    PRODUCT_SPECIFICATION(BomBillEnum.PRODUCT_SPECIFICATION),
    PRODUCT_UNIT(BomBillEnum.PRODUCT_UNIT),
    PRODUCT_NAME_HIDE(BomBillEnum.PRODUCT_NAME_HIDE),

    ;

    private BomBillEnum anEnum;

    TempBomBillEnum(BomBillEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempBomBillEnum> getAllEnum() {
        List<TempBomBillEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    /**
     * 初始化BOM单名称
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initName(FieldAttrEntity fieldAttrEntity){
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.BOM_BILL.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.BOM_BILL.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(NAME.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(0);
    }

    /**
     * 初始化BOM单编号
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initSheetNo(FieldAttrEntity fieldAttrEntity){
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.BOM_BILL.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.BOM_BILL.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(SHEET_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        // 不能重复
        fieldAttrEntity.setNoRepeat(1);
        // 默认的编号规则
        SerialNumberPoJo serialNumberPoJo = InitExplainsHelper.setSerialNumber(SerialNumberEnum.BOMBILL_NO);
        fieldAttrEntity.setSerialNumber(serialNumberPoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化BOM单状态
     * {@link com.xbongbong.saas.enums.dictionary.BomStatusEnum}
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initStatus(FieldAttrEntity fieldAttrEntity) {
//        Map<Integer, String> itemsMap = new LinkedHashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
//        itemsMap.put(1, "启用");
//        itemsMap.put(0, "禁用");
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(BomStatusEnum.class,fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(0);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化bom版本
     * 返回格式 {value: "m,,m", checked: 1}
     *
     * @param fieldAttrEntity 实体
     * @author feng.zheng
     * @date 2019/1/30 20:09
     */
    public static void initVersion(FieldAttrEntity fieldAttrEntity) {
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        JSONObject textCheck = new JSONObject();
        textCheck.put("checkText", "设为默认版本");
        textCheck.put("isDefaultCheck", 0);
        saasParticularAttributePoJo.setTextCheck(textCheck);
        saasParticularAttributePoJo.setRelyMode("product");
        saasParticularAttributePoJo.setRelyType("relied");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initFinishedProduct(FieldAttrEntity fieldAttrEntity) {
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setRelyType("base");
        saasParticularAttributePoJo.setRelyMode("product");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initMateriel(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initProductName(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.PRODUCT.getCode());
        fieldAttrEntity.setLinkedText(PRODUCT_NAME_HIDE.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    /**
     * 负责人
     * @param fieldAttrEntity
     */
    public static void initOwnerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setMultiple(1);
        fieldAttrEntity.setRequired(1);
        //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        //可删除权限：默认【超级管理员、销售主管】可删除负责人，支持自定义；
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        fieldAttrEntity.setRequired(1);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.DYNAMIC.getAlias());
        defaultAttrPoJo.setDefaultValue(DefaultValueEnum.LOGIN_USER.getValue());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.PRODUCTION_MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.PRODUCTION_MANAGER));
    }

    public static void initCoUserId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setRequired(0);
        //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增协同人，支持自定义；
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.PRODUCTION_MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.PRODUCTION_MANAGER));
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
}
